//index.js
//获取应用实例
const app = getApp()
var creaturesdata = require('../../data/creatures_data.js');  

Page({
  data: {
    creatureUrl: "http://p06iwel4h.bkt.clouddn.com/dontstarve/creatures/",
    clazz: 'Land',
  },

  showDetail: function (event) {
    var name = event.currentTarget.dataset.name;
    wx.navigateTo({
      url: '../creaturedetail/creaturedetail?Name=' + name + '&clazz=' + this.data.clazz
    })
    console.log('跳转到' + name);
  },

  changeClass: function(event) {
    var clazz = event.currentTarget.dataset.class;
    this.setData({ creatures: this.getCreatures(clazz), clazz : clazz});
  },
  
  onLoad: function () {
    this.setData({ creatures: creaturesdata.creatures.Land.Creature});
  },

  getCreatures: function (type) {
    console.log("getCreatures:" + type);
    var creatures;
    if (type == 'Land') {
      creatures = creaturesdata.creatures.Land.Creature;
    } else if (type == 'Fly') {
      creatures = creaturesdata.creatures.Fly.Creature;
    } else if (type == 'Cave') {
      creatures = creaturesdata.creatures.Cave.Creature;
    } else if (type == 'Evil') {
      creatures = creaturesdata.creatures.Evil.Creature;
    } else if (type == 'Boss') {
      creatures = creaturesdata.creatures.Boss.Creature;
    } else if (type == 'Others') {
      creatures = creaturesdata.creatures.Others.Creature;
    }
    return creatures;
  },
})
